package models

import (
	"net/url"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

var o orm.Ormer

func init() {
	orm.RegisterModel(new(User))
	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("default", "mysql", "octopoda:octopoda@/octopoda?charset=utf8&loc="+url.QueryEscape("Asia/Shanghai"))

	err := orm.RunSyncdb("default", false, true)
	if err != nil {
		beego.Error(err)
	}
	orm.Debug = true
	o = orm.NewOrm()
}

func GetOrm() orm.Ormer {
	return o
}
